package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
//日报
public class NewsPage extends BaseDomain {

    //日报文章状态常量
    public static final int STATE_NOMAL = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布
    public static final int STATE_DISABEL = -1;//禁用

    //主题
    private String title;
    //副主题
    private String subTitle;
    //创建时间
    private Date createTime;
    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GTM+8")
    private Date releaseTime;
    //封面图片
    private String coverUrl;
    //浏览数
    private Integer browseNum;
    //点赞数
    private Integer goodNum;
    //收藏数
    private Integer likeNum;
    //评论
    private Integer commentNum;

    //状态
    private Integer state = STATE_NOMAL;

    //关联日报内容对象
    private NewsContent newsContent;

    //点赞数
    //查询需要参数,评论ID,类型写死
    private Integer countZan;

    //判断某个用户是否点赞
    private int status;

    //状态形容词
    public String getStateName() {
        String str = "";
        if (state == STATE_NOMAL) {
            str = "草稿";
        } else if (state == STATE_RELEASE) {
            str = "发布";
        } else if (state == STATE_DISABEL) {
            str = "禁用";
        }
        return str;
    }

    //json字符串
    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("coverUrl", coverUrl);
        map.put("state", state);
        map.put("releaseTime", releaseTime);

        return JSONUtils.toJSONString(map);
    }

}